/*
 * @lc app=leetcode.cn id=11 lang=javascript
 *
 * [11] 盛最多水的容器
 */

// @lc code=start
/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function (height) {
    let min=function(a,b){
        return a>b?b:a
    }
    let max=function(a,b){
        return a>b?a:b
    }
    let comptedArea=function(left,right){
        return min(height[left],height[right])*(right-left)
    }
    let right=height.length-1
    let left=0
    let maxArea=min(height[left],height[right])*(right-left)
   
    while(left<right){
        if(height[left]<height[right]){
            left++
            if(min(height[left],height[right])-height[left-1]>0){
                maxArea=max(comptedArea(left,right),maxArea)
            }
        }else{
            right--
            if(min(height[left],height[right])-height[right+1]>0){
                maxArea=max(comptedArea(left,right),maxArea)
            }
        }
    }
    return maxArea
};
// @lc code=end
var maxArea = function (height) {
    let res = 0, i = 0, j = height.length - 1;
    while (i < j) {
      res = Math.max(res, Math.min(height[i], height[j]) * (j - i))
      if (height[i] < height[j]) {
        i++
      } else {
        j--
      }
    }
    return res
  }
  